<?php 
namespace Api\Controller;
use Think\Controller;
class NewVerifyController extends Controller{
	protected $apiErrorCode=0;  //接口返回的错误代码
	protected $apiErrorMsg="接口异常，请联系系统管理员或稍后再试";		//接口返回的错误信息
	public $debug=true;   //是否开启汇通接口请求返回日志记录
	
	protected $checkPram;
	
	public function _initialize(){
		//载入接口日志行为
		$this->logBehavior=new \Api\Behavior\ApiLogBehavior();
		$noVerify=array("Callback","Version"); //不需要进行签名验证的控制器
		if(!in_array(CONTROLLER_NAME, $noVerify)){
			//签名通信
			//$this->_checkVerify();
		}
		
	}
	
	/**
	 *  签名验证
	 */
	private function _checkVerify(){
		$this->checkPram=$check=array(
			"appID"=>I("post.appID"),
			"nonce"=>I("post.nonce"),
			"timeStamp"=>I("post.timeStamp"),
			"signature"=>I("post.signature"),
			"appSystem"=>I("post.appSystem"),
			"version"=>I("post.version")
		);
		//判断非空
		if (!isNotEmptyArr($check)) $this->_returnJson(array("result"=>0,"info"=>"missing field","code"=>111));
		
		//判断时间戳(误差)
		if((abs($check['timeStamp']-time()*1000) > 60*10*1000)) $this->_returnJson(array("result"=>0,"info"=>"signature timestamp out","code"=>113));
		
		//检验appID
		S(C("CACHE_MEM"));
		
		if ($rs=S("appID_".$check['appID'])) {
			$appInfo=json_decode($rs,true);
		}
		else{
			$appInfo=D("Version")->getVersion($check['appID']);
			
			if (!$appInfo) {
				$this->_returnJson(array("result"=>0,"info"=>"incorrect appID","code"=>111));
			}
			else{
				S("appID_".$check['appID'],json_encode(array('appKey'=>$appInfo['appKey'],'isOn'=>$appInfo['isOn'],'status'=>$appInfo['status'])));
			}
		}
		
		if($appInfo['isOn']==0) $this->_returnJson(array("result"=>0,"info"=>"incorrect appID","code"=>111));
		//if($appInfo['status']==0) $this->_returnJson(array("result"=>0,"info"=>"incorrect appID","code"=>145));
		if($appInfo['status']==2) $this->_returnJson(array("result"=>0,"info"=>"incorrect appID","code"=>144));
		
		$appKey=$appInfo['appKey'];
		
		//验证签名
		$signature=md5($check['appID'].$appKey.$check['nonce'].$check['timeStamp']);
		
		//file_put_contents("test.txt", "appID=".$check['appID'].",nonce=".$check['nonce'].",time=".$check['timeStamp'].",signature=".$check['signature'].",true=".$signature." 日期：".date("Y-m-d H:i:s",time()).PHP_EOL,FILE_APPEND);
		
		if ($signature!=$check['signature']) $this->_returnJson(array("result"=>0,"info"=>"incorrect signature","code"=>112));
	}
	
	//验证签名
	public function checkVerify(){
		//$this->_checkVerify();
		$this->_returnJson(array("result"=>1));
	}
	
	public function __destruct(){
		//最后做接口日志
		//B("Api\Behavior\Test");     使用自带的报错了
		
		if (!empty($this->_errorCode)) {
			$params=array(
				"errorCode"=>$this->_errorCode,
				"status"=>0
			);
		}
		else{
			$params=array(
				"errorCode"=>0,
				"status"=>1
			);
		}
		
		$this->logBehavior->run($params);
	}
	
	/** 
	 * 返回json给移动端 
	 */
	protected function _returnJson($return){
		if (!$return['result']) {
			$this->_errorCode=$return['code'];
		}
		
		//$this->ajaxReturn($return,"json",JSON_UNESCAPED_UNICODE);
		$this->ajaxReturn($return,"json");
	}
	
	protected function paging($count,$page,$pageSize){
		if ($count==0){
			$this->_returnJson(array("result"=>0,"info"=>"no data",'code'=>'139'));
		}
		$pageCount=ceil($count/$pageSize);
		if ($pageCount < $page) {
			$this->_returnJson(array("result"=>0,"info"=>"page too big","code"=>"114"));
		}
		//return $pageCount;
		return array("page"=>$page,"pageSize"=>$pageSize,"pageCount"=>$pageCount,"count"=>$count);
	}
	
	/**
	 * 记录接口错误日志
	 */
	protected function _apiErrorLog($apiName,$apiErrorMsg){
		if($this->debug==true){
			file_put_contents("log/".date("Ymd").".txt", "$apiName:$apiErrorMsg  日期：".date("Y-m-d H:i:s").PHP_EOL,FILE_APPEND);
		}
	}
	
	/**
	 * 记录接口发送日志
	 */
	protected function _requireLog($service,$url,$data,$useTime,$callback=''){
		if($this->debug==true){
			file_put_contents("log/require/".date("Ymd").".txt", "请求接口：$service 请求地址：$url 内容：".json_encode($data)." 用时：".$useTime." 返回内容：".$callback."  日期：".date("Y-m-d H:i:s").PHP_EOL,FILE_APPEND);
		}
	}
	
	/************* 请求外部营销接口类  start************/
	
	/** 
	 * 获取外部营销接口签名 
	 * @return array
	 */
	protected function _getSignature(){
		var_dump(C("APPID"));
		var_dump(C("APPKEY"));
		$data=array(
				"appId"=>C("APPID"),
				"appKey"=>C("APPKEY"),
				"nonce"=>rand(10000000, 99999999),
				"timeStamp"=>time()
		);
		
		$sort=$data;
		sort($sort,SORT_STRING);
	
		foreach ($sort as $a){
			$str.=$a;
		}

		$data['signature']=md5($str);
	
		return $data;
	}
	
	/**
	 * 调用  获取短信验证码接口 请求
	 * @param int $mobileNum 手机号码
	 * @return array
	 */
	protected function _sendSmsCode($mobileNum){
		$signature=$this->_getSignature();
	
		$send=array(
				"app"=>$signature,
				"mobileNum"=>$mobileNum
		);
		
		$result=http_post_json(C("API_GET_SMS_CODE"), json_encode($send));
		
		if ($result) {
			$msg=json_decode($result,true);
			
			if ($msg['errcode']!=0) {
				$this->_apiErrorLog("sendSmsCode", $msg['errmsg']);
				$this->apiErrorCode=$msg['errcode'];
				$this->apiErrorMsg=$msg['errmsg'];
				return false;
			}
			return $msg;
		}
		return false;
	}
	
	/**
	 * 调用  新用户注册接口 请求
	 * @param int $mobileNum 手机号
	 * @param int $smsCode 手机短信验证码
	 * @param string $password 用户设置的密码
	 * @return array bool false|array
	 */
	protected function _register($mobileNum,$smsCode,$password){
		$signature=$this->_getSignature();
	
		$send=array(
				"app"=>$signature,
				"login"=>array(
						"mobileNum"=>$mobileNum,
						"smsCode"=>$smsCode,
						"password"=>$password,
						"paymentCodeMD5"=>""
				)
		);
	
		$result=http_post_json(C("API_USER_REGISTER"), json_encode($send));
		
		if ($result) {
			$msg=json_decode($result,true);
			
			if ($msg['errcode']!=0) {
				$this->_apiErrorLog("register", $msg['errmsg']);
				$this->apiErrorCode=$msg['errcode'];
				$this->apiErrorMsg=$msg['errmsg'];
				return false;
			}
			return $msg;
		}
		return false;
	}
	
	/**
	 * 调用  用户密码登录接口 请求
	 * @param int $mobileNum 手机号
	 * @param int $smsCode 手机短信验证码
	 * @param string $password 用户设置的密码
	 * @return array bool false|array
	 */
	protected function _loginPassword($mobileNum,$password){
		$signature=$this->_getSignature();
	
		$send=array(
				"app"=>$signature,
				"login"=>array(
						"mobileNum"=>$mobileNum,
						"password"=>$password
				)
		);
	
		$result=http_post_json(C("API_LOGIN"), json_encode($send));
		
		var_dump(C("API_LOGIN"));
	    var_dump($result);exit;

		if ($result) {
			$msg=json_decode($result,true);
				
			if ($msg['errcode']!=0) {
				$this->_apiErrorLog("loginPassword", $msg['errmsg']);
				$this->apiErrorCode=$msg['errcode'];
				$this->apiErrorMsg=$msg['errmsg'];
				return false;
			}
			return $msg;
		}
		return false;
	}
	
	/**
	 * 调用  用户短信登录接口 请求
	 * @param int $mobileNum 手机号
	 * @param int $smsCode 手机短信验证码
	 * @return array bool false|array
	 */
	protected function _loginSms($mobileNum,$smsCode){
		$signature=$this->_getSignature();
	
		$send=array(
				"app"=>$signature,
				"login"=>array(
						"mobileNum"=>$mobileNum,
						"smsCode"=>$smsCode
				)
		);
	
		$result=http_post_json(C("API_SMS_LOGIN"), json_encode($send));
	
		if ($result) {
			$msg=json_decode($result,true);
	
			if ($msg['errcode']!=0) {
				$this->_apiErrorLog("loginSms", $msg['errmsg']);
				$this->apiErrorCode=$msg['errcode'];
				$this->apiErrorMsg=$msg['errmsg'];
				return false;
			}
			return $msg;
		}
		return false;
	}
	
	/**
	 * 调用  获取账户验证码接口 请求
	 * @param int $mobileNum 手机号
	 * @param int $smsCode 手机短信验证码
	 * @return array bool false|array
	 */
	protected function _getAccountCode($mobileNum){
		$signature=$this->_getSignature();
	
		$send=array(
				"app"=>$signature,
				"mobileNum"=>$mobileNum
		);
	
		$result=http_post_json(C("API_GET_ACCOUNT_CODE"), json_encode($send));
	
		if ($result) {
			$msg=json_decode($result,true);
	
			if ($msg['errcode']!=0) {
				$this->_apiErrorLog("getAccountCode", $msg['errmsg']);
				$this->apiErrorCode=$msg['errcode'];
				$this->apiErrorMsg=$msg['errmsg'];
				return false;
			}
			return $msg;
		}
		return false;
	}
	
	/**
	 * 调用  设置账户支付密码接口 请求
	 * @param int $mobileNum 手机号
	 * @param int $smsCode 手机短信验证码
	 * @return array bool false|array
	 */
	protected function _setPaymentcode($mobileNum,$accountCode,$paymentCodeMD5){
		$signature=$this->_getSignature();
		
		$send=array(
				"app"=>$signature,
				"mobileNum"=>$mobileNum,
				"accountCode"=>$accountCode,
				"paymentCodeMD5"=>$paymentCodeMD5
		);
	
		$result=http_post_json(C("API_SET_PAYMENTCODE"), json_encode($send));
	
		if ($result) {
			$msg=json_decode($result,true);
	
			if ($msg['errcode']!=0) {
				$this->_apiErrorLog("getAccountCode", $msg['errmsg']);
				$this->apiErrorCode=$msg['errcode'];
				$this->apiErrorMsg=$msg['errmsg'];
				return false;
			}
			return $msg;
		}
		return false;
	}
	
	/**
	 * 调用  重置用户登录密码（手机验证码）接口 请求
	 * @param int $mobileNum 手机号
	 * @param int $smsCode 手机短信验证码
	 * @param string $password 用户设置的密码
	 * @return array bool false|array
	 */
	protected function _reSetPassword($mobileNum,$newpassword,$smscode){
	    $signature=$this->_getSignature();
	    
	    $data=array(
			"appKey"=>C("APPKEY"),
			"nonce"=>rand(10000000, 99999999),
			"timeStamp"=>time(),
	        "mobileNum"=>"$mobileNum",
	        "newpassword"=>"$newpassword",
	        "smsCode"=>"$smscode",
	    );
	    
	     $sort=$data;
	     sort($sort,SORT_STRING);
	      
	     foreach ($sort as $a){
	       $str.=$a;
	     }
	    
	    $send=array(
	        "app"=>$signature,
	        "login"=>array(
	            "mobileNum"=>"$mobileNum",
	            "newpassword"=>"$newpassword",
	            "smsCode"=>"$smscode",
	            "timeStamp"=>$data['timeStamp'],
	            "nonce"=>$data['nonce'],
	            "signature"=>md5($str)
	        )
	    );
	    
	    /* $sort=$data;
	    sort($sort,SORT_STRING);
	    
	    foreach ($sort as $a){
	        $str.=$a;
	    } */
	    //dump($send);exit;
	
	    $result=http_post_json(C("API_RESETPASSWORD"), json_encode($send));
	     
	    if ($result) {
	        $msg=json_decode($result,true);
	
	        if ($msg['errcode']!=0) {
	            $this->_apiErrorLog("loginPassword", $msg['errmsg']);
	            $this->apiErrorCode=$msg['errcode'];
	            $this->apiErrorMsg=$msg['errmsg'];
	            return false;
	        }
	        return $msg;
	    }
	    return false;
	}
	
	/************* 请求渠道接口类  start************/
	
	/**
	 * 调用渠道接口发送请求
	 * @return 
	 */
	protected function _actionHuitongApi($service,$content){
		$url = C("HUITONG_URL").$service."/".C("HUITONG_VER")."/";
		
		$msg=array(
				"content"=>$content,
				"appNo"=>C("HUITONG_APPNO"),
				"service"=>$service,
				"ver"=>C("HUITONG_VER"),
		);
		
		$msgJson=json_encode($msg);
		
		$data = array(
				"sign"=>$this->_getHuitongSignature($msgJson),
				'appNo' => C("HUITONG_APPNO"),
				'service' => $service,
				'ver' => C("HUITONG_VER"),
				//'format' => "json",
				//'charset' => "utf-8",
				//'appKey' => C("HUITONG_APPKEY"),
				"msg"=>$msgJson
		);
		//var_dump($url);
		//var_dump($data);
		//exit;
		//echo $url;
	    //dump($data);exit;
		G('begin');
		$result=http_post($url, $data);
		G('end'); //
		$useTime=G('begin','end',6);
		$this->_requireLog($service,$url,$data,$useTime,$result);
		return $result;
	}
	
	/**
	 * 获取渠道接口签名
	 * @return str
	 */
	protected function _getHuitongSignature($msgJson){
		$data=C("HUITONG_APPKEY").$msgJson.C("HUITONG_APPKEY");
		
		$sign=base64_encode(hash("sha1", $data,true));
		return $sign;
	}
	
	/**
	 * 应用会话获取
	 * @param str $pan 汇通卡卡号
	 *  @param str $password 汇通卡卡密(已加密)
	 * @return str
	 */
	protected function _getHuitongTokenID($pan,$password){
		$data=array(
				"verifyAccntType"=>"01",
				"verifyAccntValue"=>$pan,
				"verifyPwd"=>$password,
		);
		
		$result=$this->_actionHuitongApi("channel.getTokenId",$data);
		//dump($result);
		if ($result) {
			$msg=json_decode($result,true);
		
			if ($msg['content']['respCode']!="00000") {
				$this->_apiErrorLog("getHuitongTokenID", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 获取卡号加密后的字符串
	 * @return str
	 */
	protected function _getEncryptPwd($str){
		$url=C("HUITONG_ENCRYPT_PWD");
		$data=array(
				"psw"=>$str
		);
		
		$result=http_post($url, $data);
		
		if (!$result) return false;
		
		$resultArr=json_decode($result,true);
		
		if ($resultArr['result']) {
			return $resultArr['outStr'];
		}
		return false;
	}
	
	/**
	 * 激活汇通卡
	 * @param int $pan 卡号
	 * @param str $password 卡源密码，经分配公钥证书(*.crt)加密, 再base64编码输出(传入已加密好的)
	 * @param int $verifyCode 短信验证码:短信验证码1、请求参数中verifyCode为空时，表示请求发送激活验证短信 2、接收“短信验证码”后根据卡号、卡密码、短信验证码重新发送请求进行激活
	 * @param int $mobile 持卡人手机号1、若被激活卡是非记名卡，W.S上该卡记录的手机号为购卡人手机号，则带该参数替换 2、如果第一次请求（verifyCode为空）时存在mobile参数，则第二次请求（存在verifyCode）也必须带mobile参数 
	 * @return array
	 */
	protected function _activateCard($pan,$password,$verifyCode=""){
		$data=array(
			"pan"=>$pan,
			"password"=>$password,
			//"mobile"=>$mobile,
		);
		
		if(!empty($verifyCode)) $data["verifyCode"]=$verifyCode;
		
		$result=$this->_actionHuitongApi("accnt.activateCard",$data);
		
		if ($result) {
			$msg=json_decode($result,true);
				
			if ($msg['content']['respCode']!="00000") {
				$this->_apiErrorLog("activateCard", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 汇通卡余额查询(单张)
	 * @param str $operType 查询类型 卡号:00  手机号:01 Token:03（绑定方式）
	 * @param str $operValue 查询类型为00 ：19位卡号 ;查询类型为01： 11位手机号;查询类型为03： 32位TokenId
	 * @param int $password 查询类型为00、01时，填写要求：卡源密码，经公钥证书(*.crt)加密, 再base64编码输出
	 * @return str
	 */
	protected function _getCard($operType,$operValue,$password=""){
		$data=array(
			"operType"=>$operType,
			"operValue"=>$operValue
		);
		if (!empty($password)) $data['password']=$password;
		$result=$this->_actionHuitongApi("accnt.queryCardBalance",$data);
	
		if ($result) {
			$msg=json_decode($result,true);
	
			if ($msg['content']['respCode']!="00000") {
				$this->_apiErrorLog("accnt.queryCardBalance", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 获取全部汇通卡/绑定的汇通卡余额查询(批量)
	 * @param str $operType 查询类型 卡号:00  手机号:01 Token:03（绑定方式）
	 * @param str $operValue 查询类型为00 ：19位卡号 ;查询类型为01： 11位手机号;查询类型为03： 32位TokenId
	 * @param int $password 查询类型为00、01时，填写要求：卡源密码，经公钥证书(*.crt)加密, 再base64编码输出
	 * @return str
	 */
	protected function _getAllCard($array){
		$result=$this->_actionHuitongApi("accnt.queryCardBalanceBatch",$array);
		//dump($result);
		
		if ($result) {
			$msg=json_decode($result,true);
			
			if ($msg['state']!="0000") {
				$this->_apiErrorLog("accnt.queryCardBalanceBatch", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 汇通卡消费明细
	 * @param str $operType 查询类型 卡号:00  手机号:01 Token:03（绑定方式）
	 * @param str $operValue 查询类型为00 ：19位卡号 ;查询类型为01： 11位手机号;查询类型为03： 32位TokenId
	 * @param int $pageSize 页面大小
	 * @param int $pageIndex  页面
	 * @param int $password 查询类型为00、01时，填写要求：卡源密码，经公钥证书(*.crt)加密, 再base64编码输出
	 * @param int $startDate 交易开始时间 格式YYYYMMDD
	 * @param int $endDate 交易结束时间 格式YYYYMMDD
	 * @return array
	 */
	protected function _queryCardDetail($operType,$operValue,$pageSize=10,$pageIndex=1,$password="",$startDate="",$endDate=""){
		$data=array(
				"operType"=>$operType,
				"operValue"=>$operValue,
				"pageSize"=>$pageSize,
				"pageIndex"=>$pageIndex
		);
		
		if(!empty($password)) $data['password']=$password;
		if(!empty($startDate)) $data["startDate"]=$startDate;
		if(!empty($endDate)) $data['endDate']=$endDate;
		
		$result=$this->_actionHuitongApi("accnt.queryCardDetail",$data);
		
		if ($result) {
			$msg=json_decode($result,true);
			
			if ($msg['content']['respCode']!="00000") {
				$this->_apiErrorLog("queryCardDetail", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 所有商品信息列表查询 
	 * @param int $pageSize 页面大小
	 * @param int $pageIndex  页面
	 * @return array 
	 * */ 
	protected function _queryAllCoupons($pageSize=10,$pageIndex=1){
		$result=$this->_actionHuitongApi("trade.queryAllCoupons",array("pageSize"=>$pageSize,"pageIndex"=>$pageIndex));
		
		if ($result) {
			$msg=json_decode($result,true);
				
			if ($msg['content']['respCode']!="00000") {
				$this->_apiErrorLog("queryAllCoupons", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 商品预下单
	 * @param str $couponCode 商品(电子券)编码
	 * @param str $quantity 需要购买数量
	 * @param int $mobile 电话号码
	 * @return array
	 */
	protected function _orderCouponPre($couponCode,$quantity,$mobile,$area){
		$data=array(
				"couponCode"=>"$couponCode",
				"quantity"=>"$quantity",
				"username"=>"$mobile",
				"requestType"=>"ymApp",
		        "num_area"=>$area
		);
		
		$result=$this->_actionHuitongApi("trade.orderCouponPre",$data);
		
		if ($result) {
			$msg=json_decode($result,true);
			
			if ($msg['content']['respCode']!="00000") {
				$this->_apiErrorLog("orderCouponPre", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 确认下单接口
	 * @param str $orderSn 订单序列号
	 * @param str $quantity 需要购买数量
	 * @param int $mobile 电话号码
	 * @return array
	 */
	protected function _confirmCouponOrder($orderSn,$mobile,$area){
		$data=array(
				"orderSn"=>"$orderSn",
				"username"=>$mobile,
				"requestType"=>"ymApp",
		        "num_area"=>$area
		);
		
		$result=$this->_actionHuitongApi("trade.confirmCouponOrder",$data);
		
		if ($result) {
			$msg=json_decode($result,true);
			
			if ($msg['content']['respCode']!="00000") {
				$this->_apiErrorLog("confirmCouponOrder", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 二维码信息列表查询接口
	 * @param str $orderSn 订单序列号
	 * @param str $quantity 需要购买数量
	 * @param int $mobile 电话号码
	 * @return array
	 */
	protected function _queryBarCodeList(/* $operType="02",$operValue,$password,$token, */$mobile,$pageSize=10,$pageIndex=1){
		//UserToken暂时不需要！
		/* $time=time();
		$nonce=rand(100000,999999);
		
		$userToken  = array(
				'appId' => C("APPID"),
				'timeStamp' => "$time",
				'nonce' => "$nonce",
				'token' => $token,
				"signature"=>md5(C("APPID").$nonce.$time.$token)
		); */
		
		$data=array(
				"pageSize"=>"$pageSize",
				"pageIndex"=>"$pageIndex",
				"requestType"=>"ymApp",
				//"operType"=>$operType,
				//"operValue"=>$operValue,
				//"password"=>base64_encode($password),
		        //"userToken"=>$userToken
		        "username"=>"$mobile"
		);
		
		$result=$this->_actionHuitongApi("trade.queryBarCodeList",$data);
		//echo $result;exit;
		if ($result) {
			$msg=json_decode($result,true);
			
			if ($msg['content']['respCode']) {
				$this->_apiErrorLog("queryBarCodeList", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
				$this->apiErrorCode=$msg['content']['respCode'];
				$this->apiErrorMsg=$msg['content']['respMsg'];
				return false;
			}
			return $msg['content'];
		}
		return false;
	}
	
	/**
	 * 二维码明细查询接口
	 * @param str $orderSn 订单序列号
	 * @param str $quantity 需要购买数量
	 * @param int $mobile 电话号码
	 * @return array
	 */
	protected function _queryBarCodeDetail($assisCode,$mobile/* $operType="02",$operValue,$password */){
	    //UserToken暂时不需要！
	    /* $time=time();
	     $nonce=rand(100000,999999);
	
	     $userToken  = array(
	     'appId' => C("APPID"),
	     'timeStamp' => $time,
	     'nonce' => $nonce,
	     'token' => $token,
	     "signature"=>md5(C("APPID").$nonce.$time.$token)
	     ); */
	
	    $data=array(
	        "assisCode"=>"$assisCode",
	        "requestType"=>"ymApp",
	        /* "operType"=>$operType,
	        "operValue"=>$operValue,
	        "password"=>$password */
	        "username"=>$mobile
	    );
	
	    $result=$this->_actionHuitongApi("trade.queryBarCodeDetail",$data);
	    
	    if ($result) {
	        $msg=json_decode($result,true);
	        	
	        if ($msg['content']['respCode']) {
	            $this->_apiErrorLog("queryBarCodeList", "错误代码：".$msg['content']['respCode'].",错误信息:".$msg['content']['respMsg']);
	            $this->apiErrorCode=$msg['content']['respCode'];
	            $this->apiErrorMsg=$msg['content']['respMsg'];
	            return false;
	        }
	        return $msg['content'];
	    }
	    return false;
	}
	
	protected function _getAreaNum($province,$city){
	    $rt=array(
	       "广东省"=>"GuangDong",
	       "上海市"=>"ShangHai",
	       "武汉市"=>"WuHan",
	    );
	    
	    if(!empty($rt[$city])) return $rt[$city];
	    if(!empty($rt[$province])) return $rt[$province];
	    
	    return "HSH";
	    
	}
}
?>